from pyramid.view import view_config
from pyramid.response import Response, FileResponse
from legocalendar.models.reswell.FDB import FederatedDatabase

import xlwt
import xlrd
import xlutils
from xlutils.copy import copy
from xlwt import Style, XFStyle, Borders, Pattern, easyxf
import mimetypes
import pickle
import MySQLdb
import os
import json


#helpers

FDB = FederatedDatabase()
#def makeSelectString(table)
def prettyJSON(jsonobj):
    return json.dumps(jsonobj, sort_keys=True,
                      indent=2, separators=(',', ': '))

#end helpers



# /reswell
@view_config(route_name='reswell_view', renderer='templates/reswell.pt')
def reswell_view (request):
    return { "schema" : prettyJSON(FDB.getSchema()) }


# /reswell/query_fdb
@view_config(route_name='query_fdb', renderer='string')
def query_fdb(request): 
#    print(json.dumps(request.json_body))
    x = json.dumps(FDB.query(request.json_body))
#    print(x)
    return { x }
